package br.uefs.cedoc.controle.parteII;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import br.uefs.cedoc.controle.Command;
import br.uefs.cedoc.controle.CommandException;
import br.uefs.cedoc.controle.CommandToken;
import br.uefs.cedoc.db.exception.DBConnectionException;
import br.uefs.cedoc.db.parteII.DBParteII;
import br.uefs.cedoc.entidades.ParteIIBean;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author suporte
 */
public class AddParteIICommand implements Command {
    
    private String next;
    
    public AddParteIICommand(String next) {
        this.next = next;
    }
    
    public String execute(HttpServletRequest req)
    throws CommandException {
        try {
            if(CommandToken.isValid(req)){
            DBParteII dbparteII = new DBParteII();
            ParteIIBean parteII = new ParteIIBean();            
            parteII.setNome(req.getParameter("nome"));
            parteII.setPrenome(req.getParameter("prenome"));
            
            dbparteII.criarParteII(parteII);
            req.setAttribute("status.msg", "ParteII adicionada!");
            }
            else{
                req.setAttribute("status.msg", "Nao foi possivel adicionar!");
            }
            
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (DBConnectionException ex) {
                ex.printStackTrace();
            }
        return next;

    }
}

